<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="会员推广记录" prop="hyTglogId">
									<el-input v-model="form.hyTglogId" placeholder="请输入会员推广记录" clearable></el-input>
								</el-form-item>
								<el-form-item label="推广人会员id" prop="hyAppUserId">
									<el-input v-model="form.hyAppUserId" placeholder="请输入推广人会员id" clearable></el-input>
								</el-form-item>
								<el-form-item label="微信推广 访问用户" prop="reqOpenId">
									<el-input v-model="form.reqOpenId" placeholder="请输入微信推广 访问用户" clearable></el-input>
								</el-form-item>
								<el-form-item label="访问时间" prop="reqTime">
									<el-input v-model="form.reqTime" placeholder="请输入访问时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="注册时间" prop="regTime">
									<el-input v-model="form.regTime" placeholder="请输入注册时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="第一次交易日期" prop="businessTime">
									<el-input v-model="form.businessTime" placeholder="请输入第一次交易日期" clearable></el-input>
								</el-form-item>
								<el-form-item label="取消关注时间" prop="cenTime">
									<el-input v-model="form.cenTime" placeholder="请输入取消关注时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="最后访问时间" prop="lastTime">
									<el-input v-model="form.lastTime" placeholder="请输入最后访问时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="0已访问 1已注册  8已交易 9已支付提成（已奖励） 20取消关注 21关注 28已交易 29已奖励" prop="vstate">
									<el-input v-model="form.vstate" placeholder="请输入0已访问 1已注册  8已交易 9已支付提成（已奖励） 20取消关注 21关注 28已交易 29已奖励" clearable></el-input>
								</el-form-item>
								<el-form-item label="开放平台标识" prop="unionid">
									<el-input v-model="form.unionid" placeholder="请输入开放平台标识" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '推广日志'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					hyTglogId: "",
					hyAppUserId: "",
					reqOpenId: "",
					reqTime: "",
					regTime: "",
					businessTime: "",
					cenTime: "",
					lastTime: "",
					vstate: "",
					unionid: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.hygl.hyTglog.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.hyTglogId = data.hyTglogId;
				this.form.hyAppUserId = data.hyAppUserId;
				this.form.reqOpenId = data.reqOpenId;
				this.form.reqTime = data.reqTime;
				this.form.regTime = data.regTime;
				this.form.businessTime = data.businessTime;
				this.form.cenTime = data.cenTime;
				this.form.lastTime = data.lastTime;
				this.form.vstate = data.vstate;
				this.form.unionid = data.unionid;
			}
		}
	}
</script>
<style>
</style>
